package net.awpspace.matheasy;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

public class HelpScreen extends GameCanvas implements CommandListener {

	public MathEasy main;
	Image background, pause, time, opera, answer, prepare;
	int count = -1;
	Command back;
	boolean pre = true;

	public HelpScreen(MathEasy main) {
		super(true);
		setFullScreenMode(true);
		this.main = main;
		loadContent();
		back = new Command("back", Command.BACK, 0);
		this.setCommandListener(this);
		this.addCommand(back);
	}

	private void loadContent() {
		background = ImageLoader.loadImage("/help/bghelp.png");
		pause = ImageLoader.loadImage("/help/pause.png");
		time = ImageLoader.loadImage("/help/estimate.png");
		opera = ImageLoader.loadImage("/help/opera.png");
		answer = ImageLoader.loadImage("/help/answer.png");
		prepare = ImageLoader.loadImage("/help/prepare.png");
	}

	public void paint(Graphics g) {
		super.paint(g);
		if (pre) {
			g.fillRect(0, 0, 240, 320);
			g.drawImage(prepare, 45, 118, 0);
			return;
		}
		g.drawImage(background, 0, 0, 0);
		switch (count) {
		case 0:
			g.drawImage(pause, 36, 0, 0);
			break;
		case 2:
			g.drawImage(time, 82, 16, 0);
			break;
		case 4:
			g.drawImage(opera, 55, 65, 0);
			break;
		case 6:
			g.drawImage(answer, 18, 180, 0);
			break;
		default:
			break;
		}
	}

	protected void pointerReleased(int x, int y) {
		// TODO Auto-generated method stub
		super.pointerReleased(x, y);
		if(pre){
			pre = false;
			repaint();
			return;
		}
		count++;
		if (count == 8)
			count = 0;
		System.out.println("count: " + count);
		repaint();
	}

	public void commandAction(Command c, Displayable d) {
		if (c.getLabel().equals("back")) {
			main.display.setCurrent(new MenuScreen(main));
		}

	}
}
